package testJdk.commonUse.testchar;

import cn.hutool.core.util.CharUtil;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @version 1.0.0
 * Created by cyd on 2023-07-05 12:07:06
 * @ClassName : testJdk.commonUse.testchar.TestChar
 * @Description : 类描述
 */
public class TestChar {

    /**
     * Char判断大小写
     */
    @Test
    public void test(){
        char aChar01='a';
        char aChar02='1';
        System.out.println(Character.isLowerCase(aChar01));
        System.out.println(Character.isUpperCase(aChar01));
        System.out.println(Character.isUpperCase(aChar02)); // 数字没有大小写
    }


    @Test
    public void test01() {
        char m = '罗';
        char n = '\u7f57';

        System.out.println(m);
        System.out.println(n);

        Character.UnicodeBlock result = Character.UnicodeBlock.of(m);
        System.out.println(result.toString());

        int i = CharUtil.digit16(m);
        System.out.println(i);
    }

    @Test
    public void test02() {
        String str = "你好";
        System.out.println(str);

        String str2 = "罗";
        System.out.println(str2);
        System.out.println("----------------");

        byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
        byte[] bytes1 = str.getBytes(StandardCharsets.ISO_8859_1);
        for (byte aByte : bytes) {
            System.out.println(aByte);
        }
        System.out.println("----------------");

        for (byte b : bytes1) {
            System.out.println(b);
        }
    }


    @Test
    public void test03() {
        char m = 20320;
        char n = 22909;
        System.out.println(m);
        System.out.println(n);
        char[] mn = new char[]{m, n};
        System.out.println(mn);
    }

    /**
     * 16进制数和10进制数
     */
    @Test
    public void test04() {
        char m = 32599;
        char n = '\u7f57';
        System.out.println(m);
        System.out.println(n);
    }

    /**
     * 得到字符数组
     */
    @Test
    public void test05() {
        String str = "你好";
        char[] chars = new char[2];
        str.getChars(0, 2, chars, 0);
        for (char aChar : chars) {
            System.out.println(aChar);
        }

        String str2 = "hello";
        char[] chars2 = new char[5];
        str2.getChars(0, 5, chars2, 0);
        for (char aChar : chars2) {
            System.out.println(aChar);
        }
    }

    /**
     * 字节数据和字符数据的互转
     */
    @Test
    public void test06() {
        char m;
        byte n = 75;
        m = (char) n;
        System.out.println(m);
    }

    /**
     * 字节数组转字符串
     */
    @Test
    public void test07() {
        String str = "你好大傻";
        byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
        System.out.println(Arrays.toString(bytes));
        String s = new String(bytes);
        System.out.println(s);
    }
}
